import { defineStore } from 'pinia'
import { reactive, ref } from 'vue'
import * as  userApi from '@/api/userApi'

export const useUserStore = defineStore('user', () => {

  const userRef = ref({})

  /**
   * 登录 
   * @param {String} account 
   * @param {String} password 
   * @returns {}
   */
  async function login(account, password) {
    const result = await userApi.loginUser(account, password)
    userRef.value = result.data
    return result
  }

  function loginOut() {
    userRef.value = {}
  }

  return { login, userRef, loginOut }

}, {
  persist: true
})